package com.ruoyi.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.contract.domain.InvoiceAttachment;
import com.ruoyi.contract.service.IInvoiceAttachmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发票附件Controller
 * 
 * @author ruoyi
 * @date 2024-10-18
 */
@RestController
@RequestMapping("/contract/InvoiceAttachment")
public class InvoiceAttachmentController extends BaseController
{
    @Autowired
    private IInvoiceAttachmentService invoiceAttachmentService;

    /**
     * 查询发票附件列表
     */
    @PreAuthorize("@ss.hasPermi('contract:InvoiceAttachment:list')")
    @GetMapping("/list")
    public TableDataInfo list(InvoiceAttachment invoiceAttachment)
    {
        startPage();
        List<InvoiceAttachment> list = invoiceAttachmentService.selectInvoiceAttachmentList(invoiceAttachment);
        return getDataTable(list);
    }

    /**
     * 导出发票附件列表
     */
    @PreAuthorize("@ss.hasPermi('contract:InvoiceAttachment:export')")
    @Log(title = "发票附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvoiceAttachment invoiceAttachment)
    {
        List<InvoiceAttachment> list = invoiceAttachmentService.selectInvoiceAttachmentList(invoiceAttachment);
        ExcelUtil<InvoiceAttachment> util = new ExcelUtil<InvoiceAttachment>(InvoiceAttachment.class);
        util.exportExcel(response, list, "发票附件数据");
    }

    /**
     * 获取发票附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:InvoiceAttachment:query')")
    @GetMapping(value = "/{invoiceAttachmentId}")
    public AjaxResult getInfo(@PathVariable("invoiceAttachmentId") Long invoiceAttachmentId)
    {
        return success(invoiceAttachmentService.selectInvoiceAttachmentByInvoiceAttachmentId(invoiceAttachmentId));
    }

    /**
     * 新增发票附件
     */
    @PreAuthorize("@ss.hasPermi('contract:InvoiceAttachment:add')")
    @Log(title = "发票附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InvoiceAttachment invoiceAttachment)
    {
        return toAjax(invoiceAttachmentService.insertInvoiceAttachment(invoiceAttachment));
    }

    /**
     * 修改发票附件
     */
    @PreAuthorize("@ss.hasPermi('contract:InvoiceAttachment:edit')")
    @Log(title = "发票附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InvoiceAttachment invoiceAttachment)
    {
        return toAjax(invoiceAttachmentService.updateInvoiceAttachment(invoiceAttachment));
    }

    /**
     * 删除发票附件
     */
    @PreAuthorize("@ss.hasPermi('contract:InvoiceAttachment:remove')")
    @Log(title = "发票附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{invoiceAttachmentIds}")
    public AjaxResult remove(@PathVariable Long[] invoiceAttachmentIds)
    {
        return toAjax(invoiceAttachmentService.deleteInvoiceAttachmentByInvoiceAttachmentIds(invoiceAttachmentIds));
    }
}
